package strategy;

import java.util.Collection;

import root.item.Item;
import root.item.ItemListener;
import root.item.PublicarPedido;
import root.user.User;
import exceptions.AbsentAtributException;
import exceptions.HasAlreadyDoneException;
import exceptions.InexistentCriterySortType;
import exceptions.InexistentSortType;
import exceptions.InvalidAtributException;
import exceptions.InvalidCriterySortType;
import exceptions.InvalidItemCategoryException;
import exceptions.InvalidItemNameException;
import exceptions.InvalidKeyException;
import exceptions.InvalidMessage;
import exceptions.InvalidReceiver;
import exceptions.InvalidSender;
import exceptions.InvalidSortType;
import exceptions.InvalidSubject;
import exceptions.IsNotOnwerException;
import exceptions.ItemDoesNotExist;
import exceptions.PermissionDeniedException;

/**
 * Classe gerenciadora de itens.
 */
public interface GerenciadorItemIF {
	
	public Item getItem(String id) throws ItemDoesNotExist ;
		
	public boolean hasItem(String id) ;
	
	public void addListener(ItemListener listener);
	
	public PublicarPedido getPedidoItem(String pedidoId) throws InvalidAtributException;
	
	public String addPublicarPedido(User dono, String nomeItem, String descricaoItem) throws InvalidAtributException;
	
	public void rePublicarPedido(PublicarPedido pedido) throws InvalidAtributException;
	
	public void oferecerItem(User dono, PublicarPedido pedido, String itemId) throws InvalidAtributException, ItemDoesNotExist, InvalidSender, InvalidReceiver, InvalidMessage, InvalidSubject;
	public String addItem(User owner, String name , String description, String category) throws InvalidItemNameException, InvalidItemCategoryException;
	
	public void deleteItem(User user, Item item) throws ItemDoesNotExist, IsNotOnwerException, PermissionDeniedException;
	public String getItensName(Collection<Item> items, String message) ;
	public String getItensName(Collection<Item> items) ;
	
	public void verifyKey(String key) throws InvalidKeyException ;
	
	/**
	 * Verifica se o tipo de ordenacao eh valido
	 * -Crescente
	 * -Decrecente
	 * @param ordType
	 * @return
	 * @throws InvalidSortType
	 * @throws InexistentSortType
	 */
	public boolean getSortType(String ordType) throws InvalidSortType, InexistentSortType ;
	
	
	/**
	 * Retorna uma string contendo os itens dos seus amigos
	 * que satisfazem a propriedade
	 * Key esta contido no attributo do item.
	 * Essa mesma lista esta ordenada por ordType seguindo o criterio criteyr.
	 * @param user
	 * @param key
	 * @param attri
	 * @param ordType
	 * @param critery
	 * @return
	 * @throws InvalidKeyException
	 * @throws InvalidSortType
	 * @throws InexistentSortType
	 * @throws InexistentCriterySortType
	 * @throws InvalidCriterySortType
	 * @throws InvalidAtributException
	 * @throws AbsentAtributException
	 * @throws ItemDoesNotExist
	 */
	public String searchItems(Collection<Item> items, String key, String attri, String ordType, String critery) throws InvalidKeyException, InvalidSortType, InexistentSortType, InexistentCriterySortType, InvalidCriterySortType, InvalidAtributException, AbsentAtributException, ItemDoesNotExist;
	
	/**
	 * O usuario {@code user} registra interesse no item de identidicacao {@code id}, dessa forma o usuario recebe uma mensagem
	 * offtopic quando o item esta ja esta a disposicao para emprestimo.<br>
	 * Essa mensagem é enviada por ação do evento de confirmação de termino de emprestimo pelo dono do item.
	 * 
	 * @param user
	 * @param gerenciadorItemDoUser
	 * @param item
	 * @throws ItemDoesNotExist
	 * @throws InvalidAtributException
	 * @throws PermissionDeniedException
	 * @throws HasAlreadyDoneException
	 */
	public void addItemInterest(User user, GerenciadorItemIF gerenciadorItemDoUser, Item item) throws ItemDoesNotExist, InvalidAtributException, PermissionDeniedException, HasAlreadyDoneException;
		
	public void addItemInterest(User user, GerenciadorItemIF gerenciadorItemDoUser, String itemId) throws ItemDoesNotExist, InvalidAtributException, PermissionDeniedException, HasAlreadyDoneException;
	
	public boolean hasItem(Item item);
	public String getAtributoItem(String itemId,String atributo) throws InvalidAtributException, AbsentAtributException, ItemDoesNotExist;
	
	public String getAtributoItem(Item item,String atributo) throws InvalidAtributException, AbsentAtributException, ItemDoesNotExist;
	
	public User getOwner(Item item);

	public void devolution(Item item);
	
	public void lend(Item item, User interested, int days);
	
	public Collection<Item> getItems() ;
	
	public void removeListener(ItemListener listener);
	
	public boolean contains(ItemListener listener);
}
